package com.yuhuihui.common.utils;

/**
 * byte工具类
 *
 * @author yuhh
 * @date 2023-05-25 14:02:44
 */
public final class ByteUtil {
    
    private final static char[] CS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};

    /**
     * byte数组转16进制字符串
     *
     * @param bytes 需要转换的byte数组
     * @return {@link String } 16进制字符串
     * @author yuhh
     * @date 2023-05-25 14:02:40
     */
    public static String byteArrayToHex(byte[] bytes){
        char[] cs = new char[bytes.length * 2];
        int io = 0;
        for (int n : bytes) {
            cs[io++] = CS[(n >> 4) & 0xF];
            cs[io++] = CS[(n) & 0xF];
        }
        return new String(cs);
    }
}
